
package com.joysuch.wwyt.bp.enums;

public enum ProductTypes {

    FINAL_PRODUCT("fp", "最终产品"), MIDDLE_PRODUCT("mid", "中间产品"), PRODUCT_MATIRIAL("pm", "生产原料");

    private String code;
    private String name;

    private ProductTypes(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static ProductTypes findByName(String name) {
        ProductTypes[] values = ProductTypes.values();
        for (ProductTypes v : values) {
            if (v.getName().equals(name)) {
                return v;
            }
        }
        return null;
    }

    public static ProductTypes findByCode(String code) {
        ProductTypes[] values = ProductTypes.values();
        for (ProductTypes v : values) {
            if (v.getCode().equals(code)) {
                return v;
            }
        }
        return null;
    }

    public static String findNameByCode(String code) {
        ProductTypes types = findByCode(code);
        return types == null ? null : types.name;
    }
}
